<template>
  <div>
    <!-- 主体 -->
    <section>
      <!-- 轮播图部分 -->
      <SlideShow></SlideShow>
      <!-- 商城首页 -->
      <div class="mall_main">
        <div class="container">
          <!-- 快速导航 -->
          <div class="fast_nav row">
            <div class="left">
              <a href="javascript:void(0)">
                <i class="iconfont icon-dunpai"></i>
                无忧保
              </a>
              <a href="javascript:void(0)">
                <i class="iconfont icon-integral_icon"></i>
                会员中心
              </a>
              <a href="javascript:void(0)">
                <i class="iconfont icon-yijiuhuanxin"></i>
                以旧换新
              </a>
              <a href="javascript:void(0)">
                <i class="iconfont icon-zhengpinbaozheng"></i>
                正品验证
              </a>
              <a href="javascript:void(0)">
                <i class="iconfont icon-baoxiu"></i>
                全国联保
              </a>
              <a href="javascript:void(0)">
                <i class="iconfont icon-tuihuanhuo"></i>
                无理由退换货
              </a>
            </div>
            <div class="right">
              <router-link to="/product/99">
                <img src="../assets/image/mall_index/ia_100000015.jpg" alt="" />
              </router-link>
              <router-link to="/product/2">
                <img src="../assets/image/mall_index/ia_100000016.jpg" alt="" />
              </router-link>
              <router-link to="/product/2">
                <img src="../assets/image/mall_index/ia_100000017.jpg" alt="" />
              </router-link>
            </div>
          </div>
          <!-- 活动专区 -->
          <div class="activity row">
            <h2>活动专区</h2>
            <div class="activity_left fl">
              <router-link to="/product/2">
                <img src="../assets/image/mall_index/ia_100000018.jpg" alt="" />
              </router-link>
            </div>
            <ul class="activity_right fr">
              <li v-for="(item, index) in eventsList" :key="index">
                <div class="item">
                  <router-link :to="`/product/${item.id}`">
                    <img v-lazy="item.s_goods_photos[0].path" alt="" />
                  </router-link>
                  <router-link :to="`/product/${item.id}`">
                    {{ item.desc.split("-")[0] }}
                  </router-link>
                  <span>{{ item.desc.split("-")[1] }}</span>
                  <span class="pirce">
                    <div>￥</div>
                    {{ item.sale_price || item.price }}
                  </span>
                </div>
              </li>
            </ul>
          </div>
          <!-- 热销单品 -->
          <div class="hot row">
            <h2>热销单品</h2>
            <div class="flex">
              <div class="hot_left">
                <router-link to="/product/154">
                  <img
                    src="../assets/image/mall_index/ia_100000023.jpg"
                    alt=""
                  />
                </router-link>
              </div>
              <ProductItem :products="products"></ProductItem>
            </div>
          </div>
          <!-- 通栏广告 -->
          <div class="main_ad row">
            <transition name="fade">
              <img
                v-show="show"
                src="../assets/image/mall_index/ia_100000032.jpg"
                alt=""
              />
            </transition>
            <transition name="fade">
              <img
                v-show="!show"
                src="../assets/image/mall_index/ia_100000033.jpg"
                alt=""
              />
            </transition>
          </div>
          <!-- 配件专区 -->
          <div class="parts row">
            <h2>配件专区</h2>
            <div class="parts_left fl">
              <img src="../assets/image/mall_index/ia_100000034.jpg" alt="" />
            </div>
            <ul class="parts_right fr">
              <router-link to="/peijian-list">
                <li>
                  <div class="item">
                    <img
                      src="../assets/image/mall_index/ia_100000035.png"
                      alt=""
                    />
                    <router-link to="/peijian-list"> 边刷 </router-link>
                  </div>
                </li>
              </router-link>
              <router-link to="/peijian-list">
                <li>
                  <div class="item">
                    <img
                      src="../assets/image/mall_index/ia_100000036.png"
                      alt=""
                    />
                    <router-link to="/peijian-list">拖布</router-link>
                  </div>
                </li>
              </router-link>
              <router-link to="/peijian-list">
                <li>
                  <div class="item">
                    <img
                      src="../assets/image/mall_index/ia_100000037.png"
                      alt=""
                    />
                    <router-link to="/peijian-list">滤芯</router-link>
                  </div>
                </li>
              </router-link>
              <router-link to="/peijian-list">
                <li>
                  <div class="item">
                    <img
                      src="../assets/image/mall_index/ia_100000038.png"
                      alt=""
                    />
                    <router-link to="/peijian-list">滚刷</router-link>
                  </div>
                </li>
              </router-link>
            </ul>
          </div>
          <!-- 猜你喜欢 -->
          <div class="fond row">
            <h2>猜你喜欢</h2>
            <ProductItem :products="products"></ProductItem>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";

import SlideShow from "../components/SlideShow.vue";
import ProductItem from "../components/ProductItem.vue";
export default {
  data() {
    return {
      eventsShow: [],
      show: true,
      timer: null,
    };
  },
  components: {
    SlideShow,
    ProductItem,
  },
  computed: {
    ...mapGetters("products", [
      "deebotShow",
      "winbotShow",
      "atmbotShow",
      "peijianShow",
      "events",
    ]),
    ...mapState("products", ["products"]),
    ...mapState("cart", ["cartProducts"]),
    eventsList() {
      this.eventsShow = [...this.events];
      this.eventsShow.forEach((ele) => {
        this.products.forEach((item) => {
          if (item.name == ele.name) {
            ele.id = item.id;
          }
        });
      });
      return this.eventsShow;
    },
  },
  mounted() {
    this.timer = setInterval(() => {
      this.show = !this.show;
    }, 3000);
  },
};
</script>

<style lang="scss">
@import "@/assets/css/base.scss";
body {
  section {
    margin-bottom: 45px;
    // 商城首页
    .mall_main {
      background-color: #f2f2f2;
      padding-top: 20px;
      padding-bottom: 45px;

      .container {
        width: 1220px;
        margin: 0 auto;
        // 快速导航
        .fast_nav {
          height: 174px;
          .left {
            float: left;
            width: 232px;
            height: 174px;
            padding: 17px 0;
            background: url(../assets/image/mall_index/ia_100000057.png) center
              no-repeat #fff;

            a {
              display: block;
              float: left;
              width: 75px;
              height: 58px;
              display: flex;
              flex-direction: column;
              align-items: center;
              font-size: 12px;
              color: #757575;
              text-decoration: none;

              &:hover {
                color: #ee0a3b;
              }

              i {
                display: block;
                height: 40px;
                line-height: 40px;
              }

              .iconfont {
                font-size: 31px;
              }

              &:nth-of-type(2) {
                width: 82px;
              }

              &:nth-of-type(5) {
                width: 82px;
              }

              &:nth-of-type(n + 4) {
                margin-top: 24px;
              }
            }
          }

          .right {
            float: right;

            a {
              display: block;
              width: 314px;
              height: 174px;
              float: left;

              &:hover {
                box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
              }

              &:nth-of-type(n + 2) {
                margin-left: 15px;
              }

              img {
                width: 100%;
                height: 100%;
              }
            }
          }
        }

        // 活动专区
        .activity {
          margin-top: 20px;
          overflow: hidden;
          h2 {
            font-size: 22px;
            font-weight: 500;
            color: #263746;
            margin-bottom: 14px;
            text-align: left;
          }

          .activity_left {
            transition: all 0.2s linear;
            float: left;

            &:hover {
              transform: translateY(-2px);
              box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
            }

            img {
              display: block;
              height: 340px;
            }
          }

          .activity_right {
            float: right;
            transform: translateX(15px);

            li {
              width: 247px;
              float: left;

              .item {
                width: 232px;
                height: 340px;
                margin-right: 15px;
                margin-bottom: 15px;
                display: flex;
                flex-direction: column;
                align-items: center;
                background-color: #fff;

                a {
                  display: block;
                  font-size: 16px;
                  text-decoration: none;
                  color: #263746;

                  &:first-of-type {
                    margin-bottom: 25px;
                  }
                  img {
                    width: 232px;
                    height: 200px;
                  }
                }

                span {
                  font-size: 14px;
                  color: #828282;
                }

                .pirce {
                  margin-top: 10px;
                  font-size: 16px;
                  color: #ee0a3b;

                  div {
                    display: inline-block;
                    font-size: 12px;
                  }
                }
              }
            }
          }
        }

        // 热销单品
        .hot {
          h2 {
            font-size: 22px;
            font-weight: 500;
            color: #263746;
            margin-bottom: 14px;
            text-align: left;
          }

          .flex {
            display: flex;
            overflow: hidden;
            height: 615px;
            margin-bottom: 15px;
            .hot_left {
              width: 232px;
              height: 615px;
              transition: all 0.2s linear;

              &:hover {
                transform: translateY(-2px);
                box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
              }

              img {
                display: block;
                width: 232px;
                height: 100%;
              }
            }
          }
        }

        //  通栏广告
        .main_ad {
          position: relative;
          height: 140px;
          &:hover {
            transform: translateY(-2px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
          }
          .fade-enter-active,
          .fade-leave-active {
            transition: opacity 0.5s;
          }
          .fade-enter,
          .fade-leave-to {
            opacity: 0;
          }
          .fade-enter-to,
          .fade-leave {
            opacity: 1;
          }
          img {
            position: absolute;
            top: 0;
            left: 0;
            display: block;
            width: 100%;
            height: 140px;
          }
          a {
            // transition: all 2s;

            // &:last-of-type {
            //   display: none;
            // }
          }
        }

        // 配件专区
        .parts {
          margin-top: 20px;
          overflow: hidden;
          h2 {
            font-size: 22px;
            font-weight: 500;
            color: #263746;
            margin-bottom: 14px;
            text-align: left;
          }

          .parts_left {
            float: left;
            width: 232px;
            height: 300px;
            transition: all 0.2s linear;

            &:hover {
              transform: translateY(-2px);
              box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
            }

            img {
              display: block;
              width: 100%;
              height: 100%;
            }
          }

          .parts_right {
            float: right;
            width: 988px;
            margin-bottom: 0;

            li {
              width: 232px;
              height: 300px;
              margin-left: 15px;
              margin-bottom: 15px;
              background-color: #fff;
              float: left;
              transition: all 0.2s linear;

              &:hover {
                transform: translateY(-2px);
                box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
              }

              .item {
                display: flex;
                flex-direction: column;
                align-items: center;

                a {
                  display: block;
                  font-size: 16px;
                  text-decoration: none;
                  color: #263746;
                }
              }
            }
          }
        }
        //猜你喜欢
        .fond {
          overflow: hidden;
          height: 388px;
          h2 {
            height: 33px;
            line-height: 33px;
            font-size: 22px;
            font-weight: 500;
            color: #263746;
            margin-bottom: 14px;
            text-align: left;
          }

          ul {
            li {
              width: 232px;
              height: 340px;
              margin-left: 15px;
              margin-bottom: 15px;
              background-color: #fff;
              float: left;
              transition: all 0.2s linear;

              &:hover {
                transform: translateY(-2px);
                box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
              }

              &:first-of-type {
                margin-left: 0;
              }

              .item {
                display: flex;
                flex-direction: column;
                align-items: center;

                a {
                  display: block;
                  font-size: 16px;
                  text-decoration: none;
                  color: #263746;

                  &:first-of-type {
                    margin-bottom: 25px;
                  }
                }

                span {
                  font-size: 14px;
                  color: #828282;
                }

                .pirce {
                  margin-top: 10px;
                  font-size: 16px;
                  color: #ee0a3b;

                  div {
                    display: inline-block;
                    font-size: 12px;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>